package com.hotel.front;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.hotel.BL.AuditTrailLogic;

@SuppressWarnings("serial")
public class AuditTrailService extends HttpServlet {
	
	//http://localhost:8080/auditTrailService?func=GetList&resId=resId
	//http://localhost:8080/auditTrailService?func=GetList&groupId=groupId
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		try{
			String doClass = req.getParameter("func");
			if(doClass.equals("GetList")){
				GetList(req,resp);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void GetList(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String resId = req.getParameter("resId");
		String groupId = req.getParameter("groupId");
		Object obj = null;
		if(resId != null && !resId.isEmpty())
		{
			long id = Long.parseLong(resId);
			obj = new AuditTrailLogic(req,resp).GetAuditTrailFromResvId(id);
		}
		else if(groupId != null && !groupId.isEmpty())
		{
			long id = Long.parseLong(groupId);
			obj = new AuditTrailLogic(req,resp).GetAuditTrailFromGroupId(id);
		}

		Gson gson = new Gson();

		resp.setContentType("text/plain; charset=UTF-8");
		resp.getWriter().println(gson.toJson(obj));
	}
}
